package com.sayimo.maker.user.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sayimo.framework.database.mybatis.AbstractMybatisBaseDao;
import com.sayimo.framework.exception.DaoException;
import com.sayimo.maker.user.dao.CustomerInterfaceDao;
import com.sayimo.maker.user.vo.Customer;


/**
 * @Project: sayimoWeixinApi
 * @ClassName: DeveloperinfoIterfaceImplDao
 * @Description: 微信公众号Dao
 * @Author: 王瑞清
 * @Date: 日期：2015年8月29日 时间：下午2:31:23
 * @Version 1.0.0
 */
@Repository(value = "customerInterfaceImplDao")
public class CustomerInterfaceImplDao extends AbstractMybatisBaseDao<Customer> implements CustomerInterfaceDao {
	/**
	 * 
	* @Title: queryCustomerInfo
	* @Author: 田超
	* @Date:日期：2017年2月14日 : 下午3:38:48
	* @Description:获取用户信息
	* @return Customer
	* @Version 1.0.0
	 */
	public Customer queryCustomerInfo(String accout) throws DaoException{
		return this.mybatisInterfaceBaseDao.get("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryCustomerInfo",accout);
	}
	
	public List<Customer> queryProviderId(Integer id)throws DaoException{
		return this.mybatisInterfaceBaseDao.query("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryProviderId",id);
	}
	
	public Map<String,Object> queryCustomerCount(Integer id)throws DaoException{
		return this.mybatisInterfaceBaseDao.queryMap("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryCustomerCount","num",id);
	}
	
	public List<Customer> queryChilderCustomer(Integer id)throws DaoException{
		return this.mybatisInterfaceBaseDao.query("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryChilderCustomer",id);
	}
	
	public Customer queryPeopleCode(Integer id)throws DaoException{
		return this.mybatisInterfaceBaseDao.get("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryPeopleCode",id);
	}
	
	public Customer queryBymobilePhone(String mobilePhone)throws DaoException{
		return this.mybatisInterfaceBaseDao.get("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryBymobilePhone",mobilePhone);
	}
	
	public List<Customer> queryCustomerByCond(Customer customer) throws DaoException {
		return this.mybatisInterfaceBaseDao
				.query("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryCustomerByCond", customer);
	}

	public int insertCustomer(Customer customer) throws DaoException {
		return this.mybatisInterfaceBaseDao
				.insert("com.sayimo.maker.user.dao.CustomerInterfaceDao.insertCustomer", customer);
	}

	public int updateCustomer(Customer customer) throws DaoException {
		return this.mybatisInterfaceBaseDao
				.update("com.sayimo.maker.user.dao.CustomerInterfaceDao.updateCustomer", customer);
	}
	
	public int updateModifyPhone(Customer customer) throws DaoException {
		return this.mybatisInterfaceBaseDao
				.insert("com.sayimo.maker.user.dao.CustomerInterfaceDao.updateModifyPhone", customer);
	}

	public int queryCountByAccount(String account) throws DaoException {
		return (int) this.mybatisInterfaceBaseDao
				.getObject("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryCountByAccount", account);
	}

	public Customer queryCustomerByOpenId(String openId) throws DaoException {
		return this.mybatisInterfaceBaseDao
				.get("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryCustomerByOpenId", openId);
	}

	/**
	 * @Title: getCustomerListByParentId
	 * @Description:查询会员下对应的所有下级会员信息
	 * @param parentId
	 * @throws DaoException
	 * @return List<Customer>
	 */
	public List<Customer> getCustomerListByParentId(Integer parentId) throws DaoException {
		return this.mybatisInterfaceBaseDao.query(
				"com.sayimo.maker.user.dao.CustomerInterfaceDao.getCustomerListByParentId", parentId);
	}

	
	public Integer getCustomerCountByParentId(Integer parentId) throws DaoException {
		return this.mybatisInterfaceBaseDao.queryCount(
				"com.sayimo.maker.user.dao.CustomerInterfaceDao.getCustomerCountByParentId", parentId);
	}

	@SuppressWarnings("rawtypes")
	public Map queryOrdersListCntByStatus(Customer customer,Integer mallType) throws DaoException {
		Map<String, Object> paramMap = new HashMap<>();
		paramMap.put("customerId", customer.getId());
		paramMap.put("mallType", mallType);
		Map<String, Object> map = (Map<String, Object>) this.mybatisInterfaceBaseDao.getObject(
				"com.sayimo.maker.user.dao.CustomerInterfaceDao.queryOrdersListCntByStatus", 
				paramMap);
		
		
		
		Integer payTotalCount = (Integer) this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.user.dao.CustomerInterfaceDao.getWaitCommentsCount", paramMap);
		map.put("payTotalCount", payTotalCount);
		
		paramMap.put("status", 6);
		Integer waitCommentsCount = (Integer) this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.user.dao.CustomerInterfaceDao.getWaitCommentsCount", paramMap);
		map.put("waitCommentsCount", waitCommentsCount);
		
		return map;
	}

	public Customer queryMemberCustomerById(Integer id) throws DaoException {

		return (Customer) this.mybatisInterfaceBaseDao
				.getObject("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryCustomerById", id);
	}

	@Override
	public Customer makerLogin(Customer customer) throws DaoException {
		return  this.mybatisInterfaceBaseDao.get("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryCustomerByCond",customer);
	}

	@Override
	public Customer queryByAccout(String accout) throws DaoException {
		return this.mybatisInterfaceBaseDao.get("com.sayimo.maker.user.dao.CustomerInterfaceDao.queryByAccout", accout);
	}
	
	/**
	 * @Title: getMemberMustReadList
	 * @Description:查询会员必读列表
	 * @param mark
	 * @throws DaoException
	 * @return List
	 */
	@SuppressWarnings("rawtypes")
	public List getMemberMustReadList(String mark) throws DaoException {
		return this.mybatisInterfaceBaseDao.queryObject(
				"com.sayimo.maker.user.dao.CustomerInterfaceDao.getMemberMustReadList", mark);
	}
	/**
	 * @Title: queryCustomerInfoByTime
	 * @Description:批量为用户生成二维码
	 * @param mark
	 * @throws DaoException
	 * @return List
	 */
	@Override
	public List<Customer> queryCustomerInfoByTime() throws DaoException {
		return this.mybatisInterfaceBaseDao.query(
				"com.sayimo.maker.user.dao.CustomerInterfaceDao.queryCustomerInfoByTime");
	}
	
}
